/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package samoloty.view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.SwingConstants;

/**
 *
 * @author frankowp
 */
public class InfoSubPanel extends ContentPanel {

    private MyLabel zfwLab;
    private MyLabel towLab;
    private MyLabel lawLab;
    private MyLabel actLab;
    private MyLabel act1Lab;//act zfw
    private MyLabel act2Lab;//act tow
    private MyLabel act3Lab;//act law
    private MyLabel maxLab;
    private MyLabel max1Lab;// max zfw
    private MyLabel max2Lab;// max tow
    private MyLabel max3Lab;// max law
    private MyLabel indexLab;
    private MyLabel index1Lab;// index zfw
    private MyLabel index2Lab;// index tow
    private MyLabel index3Lab;// index law
    private MyLabel pMacLab;
    private MyLabel pMac1Lab;
    private MyLabel pMac2Lab;
    private MyLabel pMac3Lab;
    private MySeparator sep1;
    private MyLabel underLoadLab;
    private MyLabel underLoadVLab;
    private MySeparator sep2;
    private MyLabel flapsLab;
    private MyLabel flaps1Lab;
    private MyLabel flaps2Lab;
    private MyLabel flaps3Lab;
    private MyLabel flaps4Lab;
    private MyLabel stabTrimLab;
    private MyLabel stabTrim1Lab;
    private MyLabel stabTrim2Lab;
    private MyLabel stabTrim3Lab;
    private MyLabel stabTrim4Lab;

    public InfoSubPanel() {
        super();
        initPanel();

    }

    private void initPanel() {
        zfwLab = new MyLabel("ZFW", MyLabel.BOLD);
        towLab = new MyLabel("TOW", MyLabel.BOLD);
        lawLab = new MyLabel("LAW", MyLabel.BOLD);
        actLab = new MyLabel("ACT", MyLabel.BOLD);
        act1Lab = new MyLabel("125678", MyLabel.BOLD);
        act2Lab = new MyLabel("125678", MyLabel.BOLD);
        act3Lab = new MyLabel("125678", MyLabel.BOLD);
        maxLab = new MyLabel("MAX", MyLabel.BOLD);
        max1Lab = new MyLabel("340010", MyLabel.BOLD);
        max2Lab = new MyLabel("340020", MyLabel.BOLD);
        max3Lab = new MyLabel("340030", MyLabel.BOLD);
        indexLab = new MyLabel("INDEX", MyLabel.BOLD);
        index1Lab = new MyLabel("1000", MyLabel.BOLD);
        index2Lab = new MyLabel("1000", MyLabel.BOLD);
        index3Lab = new MyLabel("1000", MyLabel.BOLD);
        pMacLab = new MyLabel("%MAC", MyLabel.BOLD);
        pMac1Lab = new MyLabel("-9999,99", MyLabel.BOLD);
        pMac2Lab = new MyLabel("-9999,99", MyLabel.BOLD);
        pMac3Lab = new MyLabel("-9999,99", MyLabel.BOLD);

        sep1 = new MySeparator();
        underLoadLab = new MyLabel("UNDERLOAD", MyLabel.BOLD);
        underLoadVLab = new MyLabel("640", MyLabel.BOLD);
        sep2 = new MySeparator();
        flapsLab = new MyLabel("FLAPS", MyLabel.BOLD);
        flaps1Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);

        flaps2Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);
        flaps3Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);
        flaps4Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);
        stabTrimLab = new MyLabel("STAB TRIM", MyLabel.BOLD);
        stabTrim1Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);
        stabTrim2Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);
        stabTrim3Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);
        stabTrim4Lab = new MyLabel("FLAPS 5,15, 20", MyLabel.BOLD);

        zfwLab.setHorizontalAlignment(SwingConstants.RIGHT);
        towLab.setHorizontalAlignment(SwingConstants.RIGHT);
        lawLab.setHorizontalAlignment(SwingConstants.RIGHT);
        actLab.setHorizontalAlignment(SwingConstants.RIGHT);
        act1Lab.setHorizontalAlignment(SwingConstants.RIGHT);//act zfw
        act2Lab.setHorizontalAlignment(SwingConstants.RIGHT);//act tow
        act3Lab.setHorizontalAlignment(SwingConstants.RIGHT);//act law
        maxLab.setHorizontalAlignment(SwingConstants.RIGHT);
        max1Lab.setHorizontalAlignment(SwingConstants.RIGHT);// max zfw
        max2Lab.setHorizontalAlignment(SwingConstants.RIGHT);// max tow
        max3Lab.setHorizontalAlignment(SwingConstants.RIGHT);// max law
        indexLab.setHorizontalAlignment(SwingConstants.RIGHT);
        index1Lab.setHorizontalAlignment(SwingConstants.RIGHT);// index zfw
        index2Lab.setHorizontalAlignment(SwingConstants.RIGHT);// index tow
        index3Lab.setHorizontalAlignment(SwingConstants.RIGHT);// index law
        pMacLab.setHorizontalAlignment(SwingConstants.RIGHT);
        pMac1Lab.setHorizontalAlignment(SwingConstants.RIGHT);
        pMac2Lab.setHorizontalAlignment(SwingConstants.RIGHT);
        pMac3Lab.setHorizontalAlignment(SwingConstants.RIGHT);

        this.setLayout(null);

        add(zfwLab);
        add(towLab);
        add(lawLab);
        add(actLab);
        add(act1Lab);
        add(act2Lab);
        add(act3Lab);
        add(maxLab);
        add(max1Lab);
        add(max2Lab);
        add(max3Lab);
        add(indexLab);
        add(index1Lab);
        add(index2Lab);
        add(index3Lab);
        add(pMacLab);
        add(pMac1Lab);
        add(pMac2Lab);
        add(pMac3Lab);
        add(sep1);
        add(underLoadLab);
        add(underLoadVLab);
        add(sep2);
        add(flapsLab);
        add(flaps1Lab);
        add(flaps2Lab);
        add(flaps3Lab);
        add(flaps4Lab);
        add(stabTrimLab);
        add(stabTrim1Lab);
        add(stabTrim2Lab);
        add(stabTrim3Lab);
        add(stabTrim4Lab);

        zfwLab.setPositionByRight(new Point(120, 5));
        towLab.setPositionByRight(new Point(185, 5));
        lawLab.setPositionByRight(new Point(255, 5));

        actLab.setPositionByRight(new Point(55, 30));
        act1Lab.setPositionByRight(new Point(120, 30));
        act2Lab.setPositionByRight(new Point(185, 30));
        act3Lab.setPositionByRight(new Point(255, 30));

        maxLab.setPositionByRight(new Point(55, 53));
        max1Lab.setPositionByRight(new Point(120, 53));
        max2Lab.setPositionByRight(new Point(185, 53));
        max3Lab.setPositionByRight(new Point(255, 53));


        indexLab.setPositionByRight(new Point(55, 75));
        index1Lab.setPositionByRight(new Point(120, 75));
        index2Lab.setPositionByRight(new Point(185, 75));
        index3Lab.setPositionByRight(new Point(255, 75));
        pMacLab.setPositionByRight(new Point(55, 95));
        pMac1Lab.setPositionByRight(new Point(120, 95));
        pMac2Lab.setPositionByRight(new Point(185, 95));
        pMac3Lab.setPositionByRight(new Point(255, 95));


        sep1.setPosition(new Point(0, 120));
        sep1.setSize(289, 1);

        underLoadLab.setPosition(new Point(60, 130));
        underLoadVLab.setPosition(new Point(180, 130));
        underLoadVLab.setSize(100, underLoadVLab.getSize().height);
        sep2.setPosition(new Point(0, 160));
        sep2.setSize(289, 1);

        flapsLab.setPosition(new Point(75, 170));
        flaps1Lab.setPositionByRight(new Point(150,195));
        flaps2Lab.setPositionByRight(new Point(150, 220));
        flaps3Lab.setPositionByRight(new Point(150, 245));
        flaps4Lab.setPositionByRight(new Point(150, 270));
        stabTrimLab.setPosition(new Point(150, 170));
        stabTrim1Lab.setPosition(new Point(170, 195));
        stabTrim1Lab.setSize(60, flapsLab.getSize().height);
        stabTrim2Lab.setPosition(new Point(170, 220));
        stabTrim2Lab.setSize(60, flapsLab.getSize().height);
        stabTrim3Lab.setPosition(new Point(170, 245));
        stabTrim3Lab.setSize(60, flapsLab.getSize().height);
        stabTrim4Lab.setPosition(new Point(170, 270));
        stabTrim4Lab.setSize(60, flapsLab.getSize().height);

    }

    public void reset() {
        stabTrim1Lab.setVisible(true);
        stabTrim2Lab.setVisible(true);
        stabTrim3Lab.setVisible(true);
        stabTrim4Lab.setVisible(true);

        flaps1Lab.setVisible(true);
        flaps2Lab.setVisible(true);
        flaps3Lab.setVisible(true);
        flaps4Lab.setVisible(true);

        stabTrim1Lab.setText("0");
        stabTrim2Lab.setText("0");
        stabTrim3Lab.setText("0");
        stabTrim4Lab.setText("0");

        flaps1Lab.setText("1");
        flaps2Lab.setText("2");
        flaps3Lab.setText("3");
        flaps4Lab.setText("4");

        unhilight_valaw();
        unhilight_vatow();
        unhilight_vazfw();
        unhilight_vlawi();
        unhilight_vtowi();
        unhilight_vul();
        unhilight_vzfwi();
    }

    public void setFlaps1Lab(String t) {
        flaps1Lab.setText(t);
        if (t.equals("")) {
            flaps1Lab.setVisible(false);
        } else {
            flaps1Lab.setVisible(true);
        }
    }

    public void setFlaps2Lab(String t) {
        flaps2Lab.setText(t);
        if (t.equals("")) {
            flaps2Lab.setVisible(false);
        } else {
            flaps2Lab.setVisible(true);
        }
    }

    public void setFlaps3Lab(String t) {
        flaps3Lab.setText(t);
        if (t.equals("")) {
            flaps3Lab.setVisible(false);
        } else {
            flaps3Lab.setVisible(true);
        }
    }

    public void setFlaps4Lab(String t) {
        flaps4Lab.setText(t);
        if (t.equals("")) {
            flaps4Lab.setVisible(false);
        } else {
            flaps4Lab.setVisible(true);
        }
    }

    public void setStabTrim1Lab(String t) {
        stabTrim1Lab.setText(t);
        stabTrim1Lab.setVisible(true);
        if (t.equals("")) {
            stabTrim1Lab.setVisible(false);
        } else {
            stabTrim1Lab.setVisible(true);
        }
    }

    public void setStabTrim2Lab(String t) {
        stabTrim2Lab.setText(t);
        if (t.equals("")) {
            stabTrim2Lab.setVisible(false);
        } else {
            stabTrim2Lab.setVisible(true);
        }
    }

    public void setStabTrim3Lab(String t) {
        stabTrim3Lab.setText(t);
        if (t.equals("")) {
            stabTrim3Lab.setVisible(false);
        } else {
            stabTrim3Lab.setVisible(true);
        }
    }

    public void setStabTrim4Lab(String t) {
        stabTrim4Lab.setText(t);
        if (t.equals("")) {
            stabTrim4Lab.setVisible(false);
        } else {
            stabTrim4Lab.setVisible(true);
        }
    }

    public void set_vazfw(double value) {
        this.act1Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vatow(double value) {
        this.act2Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_valaw(double value) {
        this.act3Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vmzfw(double value) {
        this.max1Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vmtow(double value) {
        this.max2Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vmlaw(double value) {
        this.max3Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vzfwi(double value) {
        this.index1Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vtowi(double value) {
        System.err.println("Przekazana wartosc" + value);
        this.index2Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vlawi(double value) {
        this.index3Lab.setText(Integer.toString((int) Math.round(value)));
    }

    public void set_vul(double value) {
        this.underLoadVLab.setText(Integer.toString((int) Math.round(value)));
    }

    public void hilight_vul() {
        underLoadVLab.setForeground(Color.red);
        underLoadVLab.setName("invalid");
    }

    public void unhilight_vul() {
        underLoadVLab.setForeground(Color.LIGHT_GRAY);
        underLoadVLab.setName(null);
    }

    public void hilight_vazfw() {
        act1Lab.setForeground(Color.red);
        act1Lab.setName("invalid");
    }

    public void unhilight_vazfw() {
        act1Lab.setForeground(Color.LIGHT_GRAY);
        act1Lab.setName(null);
    }

    public void hilight_vatow() {
        act2Lab.setForeground(Color.red);
        act2Lab.setName("invalid");
    }

    public void unhilight_vatow() {
        act2Lab.setForeground(Color.LIGHT_GRAY);
        act2Lab.setName(null);
    }

    public void hilight_valaw() {
        act3Lab.setForeground(Color.red);
        act3Lab.setName("invalid");
    }

    public void unhilight_valaw() {
        act3Lab.setForeground(Color.LIGHT_GRAY);
        act3Lab.setName(null);
    }

    public void hilight_vzfwi() {
        index1Lab.setForeground(Color.red);
        index1Lab.setName("invalid");
    }

    public void unhilight_vzfwi() {
        index1Lab.setForeground(Color.LIGHT_GRAY);
        index1Lab.setName(null);
    }

    public void hilight_vtowi() {
        index2Lab.setForeground(Color.red);
        index2Lab.setName("invalid");
    }

    public void unhilight_vtowi() {
        index2Lab.setForeground(Color.LIGHT_GRAY);
        index2Lab.setName(null);
    }

    public void hilight_vlawi() {
        index3Lab.setForeground(Color.red);
        index3Lab.setName("invalid");
    }

    public void unhilight_vlawi() {
        index3Lab.setForeground(Color.LIGHT_GRAY);
        index3Lab.setName(null);
    }

    public void set_vmaclaw(String vmaclaw) {
        pMac3Lab.setText(vmaclaw);
    }

    public void set_vmactow(String vmactow) {
        pMac2Lab.setText(vmactow);
    }

    public void set_vmaczfw(String vmaczfw) {
        pMac1Lab.setText(vmaczfw);
    }

    @Override
    public boolean isValid() {
        try {
            Component[] components = this.getComponents();
            for (int i = 0; i < components.length; i++) {
                if (components[i].getName() != null) {
                    return false;
                }
            }
            return true;
        } catch (NullPointerException e) {
            return false;
        }
    }
}
